//
//  ZYProgressView.m
//  DistributorAB
//
//  Created by 主事丫环 on 2019/8/21.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "ZYProgressView.h"


@interface ZYProgressView() {
    UIView *viewTop;
    UIView *viewBottom;
}
@end

@implementation ZYProgressView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self buildUI];
    }
    return self;
}

- (void)buildUI {
    
    viewBottom = [[UIView alloc]initWithFrame:self.bounds];
    viewBottom.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
    //viewBottom.layer.cornerRadius = 3;
    //viewBottom.layer.masksToBounds = YES;
    [self addSubview:viewBottom];
    
    viewTop = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, viewBottom.frame.size.height)];
    viewTop.backgroundColor = [UIColor colorWithHexString:@"#84DB33"];
    //viewTop.layer.cornerRadius = 3;
    //viewTop.layer.masksToBounds = YES;
    [viewBottom addSubview:viewTop];
}

-(void)setTime:(float)time {
    _time = time;
}

-(void)setProgressValue:(NSString *)progressValue {
    if (!_time) {
        _time = 1.0f;
    }
    _progressValue = progressValue;
    [UIView animateWithDuration:_time animations:^{
        viewTop.frame = CGRectMake(viewTop.frame.origin.x, viewTop.frame.origin.y, viewBottom.frame.size.width*[progressValue floatValue], viewTop.frame.size.height);
    }];
}

-(void)setBottomColor:(UIColor *)bottomColor {
    _bottomColor = bottomColor;
    viewBottom.backgroundColor = bottomColor;
}

-(void)setProgressColor:(UIColor *)progressColor {
    _progressColor = progressColor;
    viewTop.backgroundColor = progressColor;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
